home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1608 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  7.3 KB

  1. Subject: fselect for exceptional conditions patch...
  2. Date: Mon, 20 Jun 94 15:10:14 +0100
  3. From: Torsten Scherer <itschere@techfak.uni-bielefeld.de>
  4.  
  5.  Hi fellas!
  6.  
  7.  Now here's something which might interest you: A patch to add the
  8. functionality to select for exceptional conditions to MiNT. The patch
  9. is relative to Michael Hohmuth's 1.10 V3 meta patch.
  10.  
  11.  Note that this does *not* say there currently is any device driver which
  12. supports this! I merely did it so that Kay Roemer can use it in his socket
  13. device, because I think we'll need it for telnet and things like this. Since
  14. he already depends on `unofficial' patches, there isn't much point in
  15. mocking about adding an extra one.. ;)
  16.  
  17.  A device driver which want's to support this must also support a select
  18. mode of 2 (besides 0 for `read' and 1 for 'write', which all drivers should
  19. support) and should implement an FIOEXCEPT ioctl call to determine if a
  20. particular file pointers has got an exceptional condition to offer (just
  21. like FIONREAD and FIONWRITE for read/write selects), in which case it
  22. should set it's argument pointer to 1.
  23.  
  24.  If you should select an old device driver for exceptional conditions, it
  25. should just behave the way it has done without this, say block, because it
  26. neither understands the select mode 2 (and therefore can't be activated to
  27. select), nor the FIOEXCEPT call (and therefore won't never report success).
  28. Since this is only theory and even MiNT's internal device drivers do not
  29. always explicitly check both of the `old' possible modes, but use constructs
  30. like `if (mode != O_RDONLY)', some patches have been necessary to be sure.
  31. At least it doesn't seem to disturb my setup now... :-)
  32.  
  33.  But then, I didn't had a great chance to test the *real* goal... ;)
  34.  
  35. ciao,
  36. TeSche
  37. --
  38. Torsten Scherer (TeSche, Schiller...)
  39. Faculty of Technology, University of Bielefeld, Germany, Europe, Earth...
  40. | Use any of "finger itschere@129.70.131.2-15" for adresses and more.|
  41. | Last updated: 14. April 1994.|
  42.  
  43.  
  44. --- file.h.origSun Jun 19 17:54:16 1994
  45. +++ file.hSun Jun 19 18:31:18 1994
  46. @@ -340,6 +340,7 @@
  47.  #define FSTAT(('F'<< 8) | 0)/* handled by kernel */
  48.  #define FIONREAD(('F'<< 8) | 1)
  49.  #define FIONWRITE(('F'<< 8) | 2)
  50. +#define FIOEXCEPT(('F'<< 8) | 3)
  51.  #define TIOCGETP(('T'<< 8) | 0)
  52.  #define TIOCSETN(('T'<< 8) | 1)
  53.  #define TIOCGETC(('T'<< 8) | 2)
  54. --- dosfile.c.origSun Jun 19 17:54:26 1994
  55. +++ dosfile.cSun Jun 19 17:54:24 1994
  56. @@ -954,11 +954,11 @@
  57.   * integers containing bitmasks that describe which file descriptors
  58.   * we're interested in. These masks are changed to represent which
  59.   * file descriptors actually have data waiting (rfd), are ready to
  60. - * output (wfd), or have exceptional conditions (xfd -- currently
  61. - * ignored). If timeout is 0, fselect blocks until some file descriptor
  62. - * is ready; otherwise, it waits only "timeout" milliseconds.
  63. - * Return value: number of file descriptors that are available for
  64. - * reading/writing; or a negative error number.
  65. + * output (wfd), or have exceptional conditions (xfd). If timeout is 0,
  66. + * fselect blocks until some file descriptor is ready; otherwise, it
  67. + * waits only "timeout" milliseconds. Return value: number of file
  68. + * descriptors that are available for reading/writing; or a negative
  69. + * error number.
  70.   */
  71.  
  72.  /* helper function for time outs */
  73. @@ -974,7 +974,7 @@
  74.  unsigned timeout;
  75.  long *rfdp, *wfdp, *xfdp;
  76.  {
  77. -long rfd, wfd;
  78. +long rfd, wfd, xfd;
  79.  long mask, bytes;
  80.  int i, count;
  81.  FILEPTR *f;
  82. @@ -982,9 +982,6 @@
  83.  TIMEOUT *t;
  84.  short sr;
  85.  
  86. -if (xfdp)
  87. -*xfdp = 0;
  88. -
  89.  if (rfdp) {
  90.  rfd = *rfdp; *rfdp = 0;
  91.  }
  92. @@ -995,14 +992,19 @@
  93.  }
  94.  else
  95.  wfd = 0;
  96. +if (xfdp) {
  97. +xfd = *xfdp; *xfdp = 0;
  98. +}
  99. +else
  100. +xfd = 0;
  101.  
  102. -TRACE(("Fselect(%u, %lx, %lx)", timeout, rfd, wfd));
  103. +TRACE(("Fselect(%u, %lx, %lx, %lx)", timeout, rfd, wfd, xfd));
  104.  p = curproc;/* help the optimizer out */
  105.  
  106.  /* first, validate the masks */
  107.  mask = 1L;
  108.  for (i = 0; i < MAX_OPEN; i++) {
  109. -if ( ((rfd & mask) || (wfd & mask)) && !(p->handle[i]) ) {
  110. +if ( ((rfd & mask) || (wfd & mask) || (xfd & mask)) && !(p->handle[i]) ) {
  111.  DEBUG(("Fselect: invalid handle: %d", i));
  112.  return EIHNDL;
  113.  }
  114. @@ -1044,6 +1046,17 @@
  115.  *wfdp |= mask;
  116.  }
  117.  }
  118. +if (xfd & mask) {
  119. +f = p->handle[i];
  120. +/* tesche: anybody worried about using O_RDWR for exceptional data? ;) */
  121. +if ((*f->dev->select)(f, (long)p, O_RDWR) == 1) {
  122. +/*  tesche: for old device drivers, which don't understand this
  123. + * call, this will never be true and therefore won't disturb us here.
  124. + */
  125. +count++;
  126. +*xfdp |= mask;
  127. +}
  128. +}
  129.  mask = mask << 1L;
  130.  }
  131.  
  132. @@ -1106,6 +1119,20 @@
  133.      }
  134.  }
  135.  }
  136. +if (xfd & mask) {
  137. +f = p->handle[i];
  138. +if (f) {
  139. +/*  tesche: since old device drivers won't understand this call,
  140. + * we set up `no exceptional condition' as default.
  141. + */
  142. +    bytes = 0L;
  143. +    (void)(*f->dev->ioctl)(f, FIOEXCEPT,&bytes);
  144. +    if (bytes > 0) {
  145. +*xfdp |= mask;
  146. +count++;
  147. +    }
  148. +}
  149. +}
  150.  mask = mask << 1L;
  151.  }
  152.  }
  153. @@ -1125,6 +1152,11 @@
  154.  if (f)
  155.  (*f->dev->unselect)(f, (long)p, O_WRONLY);
  156.  }
  157. +if (xfd & mask) {
  158. +f = p->handle[i];
  159. +if (f)
  160. +(*f->dev->unselect)(f, (long)p, O_RDWR);
  161. +}
  162.  mask = mask << 1L;
  163.  }
  164.  
  165. --- biosfs.c.origMon Jun 20 14:28:52 1994
  166. +++ biosfs.cMon Jun 20 14:33:36 1994
  167. @@ -1090,11 +1090,12 @@
  168.  FILEPTR *f; int mode; void *buf;
  169.  {
  170.  UNUSED(f);
  171. -if (mode == FIONREAD) {
  172. +if (mode == FIONREAD)
  173.  *((long *)buf) = 0;
  174. -}
  175.  else if (mode == FIONWRITE)
  176.  *((long *)buf) = 1;
  177. +else if (mode == FIOEXCEPT)
  178. +*((long *)buf) = 0;
  179.  else
  180.  return EINVFN;
  181.  return 0;
  182. @@ -1130,8 +1131,10 @@
  183.  int mode;
  184.  {
  185.  UNUSED(f); UNUSED(p);
  186. -UNUSED(mode);
  187. -return 1;/* we're always ready to read/write */
  188. +if ((mode == O_RDONLY) || (mode == O_WRONLY))
  189. +return 1;/* we're always ready to read/write */
  190. +
  191. +return 0;/* other things we don't care about */
  192.  }
  193.  
  194.  void ARGS_ON_STACK 
  195. @@ -1339,6 +1342,9 @@
  196.  else
  197.  *r = 0;
  198.  break;
  199. +case FIOEXCEPT:
  200. +*r = 0;
  201. +break;
  202.  case TIOCFLUSH:
  203.      {
  204.  int oldmap;
  205. @@ -1878,6 +1884,10 @@
  206.  if (r < 0) r += MOUSESIZ;
  207.  *((long *)buf) = r;
  208.  }
  209. +else if (mode == FIONWRITE)
  210. +*((long *)buf) = 0;
  211. +else if (mode == FIOEXCEPT)
  212. +*((long *)buf) = 0;
  213.  else
  214.  return EINVFN;
  215.  return 0;
  216. @@ -1891,8 +1901,12 @@
  217.  {
  218.  UNUSED(f);
  219.  
  220. -if (mode != O_RDONLY)
  221. -return 1;/* we can always take output :-) */
  222. +if (mode != O_RDONLY) {
  223. +if (mode == O_WRONLY)
  224. +return 1;/* we can always take output :-) */
  225. +else
  226. +return 0;/* but don't care for anything else */
  227. +}
  228.  
  229.  if (mousetail - mousehead)
  230.  return 1;/* input waiting already */
  231. --- fasttext.c.origMon Jun 20 14:28:38 1994
  232. +++ fasttext.cMon Jun 20 14:30:48 1994
  233. @@ -1322,6 +1322,9 @@
  234.  else if (mode == FIONWRITE) {
  235.  *r = 1;
  236.  }
  237. +else if (mode == FIOEXCEPT) {
  238. +*r = 0;
  239. +}
  240.  else if (mode == TIOCFLUSH) {
  241.  /* BUG: this should flush the input/output buffers */
  242.  return 0;
  243. --- pipefs.c.origMon Jun 20 14:35:42 1994
  244. +++ pipefs.cMon Jun 20 14:37:16 1994
  245. @@ -782,6 +782,9 @@
  246.  }
  247.  *((long *) buf) = r;
  248.  break;
  249. +case FIOEXCEPT:
  250. +*((long *) buf) = 0;
  251. +break;
  252.  case F_SETLK:
  253.  case F_SETLKW:
  254.  lck = (struct flock *)buf;
  255. --- procfs.c.origMon Jun 20 14:37:30 1994
  256. +++ procfs.cMon Jun 20 14:38:08 1994
  257. @@ -693,6 +693,9 @@
  258.  case FIONWRITE:
  259.  *((long *)buf) = 1L;/* we're always ready for i/o */
  260.  return 0;
  261. +case FIOEXCEPT:
  262. +*((long *)buf) = 0L;
  263. +return 0;
  264.  default:
  265.  DEBUG(("procfs: bad Fcntl command"));
  266.  }
  267. --- tosfs.c.origMon Jun 20 14:34:46 1994
  268. +++ tosfs.cMon Jun 20 14:35:04 1994
  269. @@ -1314,6 +1314,9 @@
  270.  case FIONWRITE:
  271.  *((long *)buf) = 1;
  272.  return 0;
  273. +case FIOEXCEPT:
  274. +*((long *)buf) = 0;
  275. +return 0;
  276.  case F_SETLK:
  277.  case F_SETLKW:
  278.  case F_GETLK:
  279.